package com.cy.member;

import java.awt.Cursor;
import java.awt.Point;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.SwingConstants;

import com.cy.listener.BackListener;
import com.cy.listener.EndListener;
import com.cy.listener.NewListener;
import com.cy.listener.GameTypeListener;
import com.cy.listener.SoundEffectListener;
import com.cy.listener.BackgroundMusicListener;
import com.cy.listener.SyncMoveListener;
import com.cy.member.parent.CYWindow;
/**
 * 控制面板
 * @author CY
 */
public class ControlPanel extends CYWindow {
	private static final long serialVersionUID = 1L;
	//控制面板尺寸
	private ImageIcon bgImg = new ImageIcon("image/ControlPanel.jpg"); 
	//显示谁出棋
	private JLabel who;
	
	/**
	 * @param locatin 棋盘的位置
	 */
	public ControlPanel(Point locatin) {
		init(locatin);
		SyncMoveListener syncMoveListener = new SyncMoveListener();
		this.addMouseListener(syncMoveListener);
		this.addMouseMotionListener(syncMoveListener);
	}

	/**
	 * 初始化
	 * @param locatin
	 */
	private void init(Point locatin) {
		//添加该谁出棋
		who = new JLabel("红方出棋",new ImageIcon("image/红将.gif"),SwingConstants.CENTER);
		who.setBounds(10, 30, 105, 85);
		who.setVerticalTextPosition(JLabel.BOTTOM);
		who.setHorizontalTextPosition(JLabel.CENTER);
		this.add(who);
		//添加背景音乐开关
		JLabel BackgroundMusic = new JLabel("背景音乐：",new ImageIcon("image/turnon.png"),SwingConstants.LEFT);
		BackgroundMusic.setBounds(15, 150, 105, 32);
		BackgroundMusic.setHorizontalTextPosition(JLabel.LEFT);
		BackgroundMusic.addMouseListener(new BackgroundMusicListener());
		this.add(BackgroundMusic);
		//添加游戏音效开关
		JLabel soundEffect = new JLabel("游戏音效：",new ImageIcon("image/turnon.png"),SwingConstants.LEFT);
		soundEffect.setBounds(15, 200, 105, 32);
		soundEffect.setHorizontalTextPosition(JLabel.LEFT);
		soundEffect.addMouseListener(new SoundEffectListener());
		this.add(soundEffect);
		//结束游戏按钮
		JLabel end = new JLabel("结束游戏：",new ImageIcon("image/exit.png"),SwingConstants.LEFT);
		end.setBounds(15, 250, 105, 32);
		end.setHorizontalTextPosition(JLabel.LEFT);
		end.addMouseListener(new EndListener());
		this.add(end);
		//添加新局
		JLabel newJL = new JLabel(new ImageIcon("image/new.jpg"),SwingConstants.CENTER);
		newJL.setBounds(0, 300, 128, 50);
		newJL.addMouseListener(new NewListener());
		this.add(newJL);
		//添加悔棋
		JLabel back = new JLabel(new ImageIcon("image/back.jpg"),SwingConstants.CENTER);
		back.setBounds(0, 370, 128, 50);
		back.addMouseListener(new BackListener());
		this.add(back);
		//添加游戏模式切换
		JLabel gameType = new JLabel(new ImageIcon("image/jingdian.jpg"),SwingConstants.CENTER);
		gameType.setBounds(0,440, 128, 50);
		gameType.addMouseListener(new GameTypeListener());
		this.add(gameType);
		//署名
		JLabel name = new JLabel("Powered by CY.",SwingConstants.CENTER);
		name.setBounds(0, 530, 128, 30);
		this.add(name);
		//添加背景
		JLabel background = new JLabel(bgImg);
		background.setBounds(0, 0, bgImg.getIconWidth(), bgImg.getIconHeight());
		this.add(background);
		//设置默认属性
		this.setLayout(null);
		this.setSize(bgImg.getIconWidth(), bgImg.getIconHeight());
		this.setCursor(new Cursor(Cursor.HAND_CURSOR));
		this.setLocation(locatin.x+558,locatin.y);
	}

	/**
	 * 显示该谁出棋
	 * @param who
	 */
	public void setWho(Boolean who) {
		if(who) {//红方
			this.who.setText("红方出棋");
			this.who.setIcon(new ImageIcon("image/红将.gif"));
		} else {
			this.who.setText("黑方出棋");
			this.who.setIcon(new ImageIcon("image/黑将.gif"));
		}
	}
	
}
